﻿// See https://aka.ms/new-console-template for more information
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Net.Http.Headers;
using System.Net;
using Minio.DataModel.Args;
using System.Security.AccessControl;
using Minio;
using System.IO;
using System.Net.Mime;
using System.Runtime.Intrinsics.X86;
using HeyRed.Mime;

Console.WriteLine("Hello, World!");

//https://www.wenjiangs.com/doc/minio-dotnet-client-api-reference
string ak = "minioadmin";
string sk = "minioadmin";
string bucket = "test";
string endpoint = "192.168.2.137:9001";

var c = new MinioClient().WithEndpoint(endpoint).WithCredentials(ak, sk).Build();
var bucks = await c.ListBucketsAsync();
foreach( var b in bucks.Buckets)
{
    Console.WriteLine(b.Name);
}
var obj = new StatObjectArgs()
    .WithBucket(bucket)
    .WithObject("/1.png");
var res = await c.StatObjectAsync(obj);
Console.WriteLine(res.Size);

string fileLoc = @"F:\ftp\0.png";
var contentType = MimeTypesMap.GetMimeType(fileLoc);
Console.WriteLine(contentType);
MemoryStream s = new MemoryStream(File.ReadAllBytes(fileLoc));
var ag = new PutObjectArgs()
                                       .WithBucket(bucket)
                                       .WithObject("/test.png")
                                       .WithStreamData(s)
                                       .WithContentType(contentType)
                                       .WithObjectSize(s.Length)
                                       ;
var ret = await c.PutObjectAsync(ag);
Console.WriteLine(ret.Etag);